package com.liujiaqi.controller;

import com.liujiaqi.pojo.Address;
import com.liujiaqi.pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/*
* 测试响应数据
*/
@RestController
public class ResponseController {

/*  @RequestMapping("/hello")
  public String hello() {
    System.out.println("Hello World ~");
    return "Hello World ~";
  }

  @RequestMapping("/getAddress")
  public Address getAddress() {
    Address address = new Address("广东省","佛山市");
    return address;
  }

  @RequestMapping("/listAddress")
  public List<Address> listAddress() {
    List<Address> list = new ArrayList<>();

    list.add(new Address("广东省","佛山市"));
    list.add(new Address("湖南省","祁东县"));

    return list;
  }*/

  @RequestMapping("/hello")
  public Result hello() {
    System.out.println("Hello World ~");
    return Result.success("Hello World ~");
  }

  @RequestMapping("/getAddress")
  public Result getAddress() {
    Address address = new Address("广东省","佛山市");
    return Result.success(address);
  }

  @RequestMapping("/listAddress")
  public Result listAddress() {
    List<Address> list = new ArrayList<>();

    list.add(new Address("广东省","佛山市"));
    list.add(new Address("湖南省","祁东县"));

    return Result.success(list);
  }

  @RequestMapping("/randomOrdering")
  public Result randomOrdering() {
    String[] list = {"猪脚","木桶","蒸饭"};
    Random r = new Random();
    return Result.success("恭喜你选中了：" + list[r.nextInt(list.length)]);
  }
}
